package com.ruoyi.ruoyiserver.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ruoyiserver.domain.PeDataInformation;
import com.ruoyi.ruoyiserver.domain.PeObligeeInformtion;
import com.ruoyi.ruoyiserver.domain.PeRecord;
import com.ruoyi.ruoyiserver.domain.PeStudentInformation;
import com.ruoyi.ruoyiserver.mapper.PeDataInformationMapper;
import com.ruoyi.ruoyiserver.mapper.PeRecordMapper;
import com.ruoyi.ruoyiserver.service.IPeDataInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/person/data-information")
@Api(tags = "查询信息")
public class PeDataInformationController extends BaseController {
    @Autowired
    private IPeDataInformationService peDataInformationService;
    @Resource
    private PeDataInformationMapper peDataInformationMapper;
    @Resource
    private PeRecordMapper peRecordMapper;

    /*查询*/
    @GetMapping("/list")
    public TableDataInfo list(PeDataInformation peDataInformation)
    {
        startPage();
        List<PeDataInformation> list = peDataInformationService.selectPeDataInformationList(peDataInformation);
        PeRecord peRecord = new PeRecord();
        BeanUtils.copyProperties(peDataInformation,peRecord);
        peRecord.setAccount(SecurityUtils.getLoginUser().getUsername());
        long l = System.currentTimeMillis();
        Date date = new Date(l);
        peRecord.setCreateTime(date);
        peRecordMapper.insertPeRecord(peRecord);
        return getDataTable(list);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    // @PreAuthorize("@ss.hasPermi('person:informtion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(peDataInformationService.selectPeObligeeInformtionById(id));
    }

    /*增加*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PeDataInformation peDataInformation)
    {
        peDataInformation.setId(UUID.randomUUID().toString().replace("-", "").substring(0, 20));
        return toAjax(peDataInformationMapper.insert(peDataInformation));
    }

    /*修改*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult edit(@RequestBody PeDataInformation peDataInformation)
    {
        return toAjax(peDataInformationMapper.updateById(peDataInformation));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(peDataInformationMapper.deleteBatchIds(Arrays.asList(ids)));
    }
}
